<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\analysis\report;

use app\enum\AnalysisEnum;
use app\model\mongo\MongoReportModel;
use app\service\analysis\AnalysisService;
use app\service\BaseService;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

/**
 * @property int $mediaId
 */
abstract class ReportService extends BaseService
{
    /**
     * 获取媒体ID.
     */
    public static function getMediaId(): int
    {
        return static::$mediaId;
    }

    /**
     * 获取数据类型.
     */
    public static function getDataType(): string
    {
        return AnalysisEnum::TASK_TYPE_ARRAY[static::$taskType];
    }

    /**
     * 获取报表表模型.
     */
    public static function getModel(): MongoReportModel
    {
        return AnalysisService::getReportModel(self::getMediaId(), self::getDataType());
    }

    /**
     * 获取分页数据.
     *
     * @param array $where 查询条件
     * @param int $page 分页数
     * @param int $limit 分页值
     * @return array|Collection|MongoReportModel[]
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getList(array $where = [], int $page = 1, int $limit = 200)
    {
        return self::getModel()->where($where)->limit(($page - 1) * $limit, $limit)->select();
    }
}
